<template>
  <view :class="showStr" @click="cancel">
    <view class="content">
      <view class="title">
        <text>{{ titleData }}</text>
      </view>
      <view class="c1">
        <slot></slot>
      </view>
      <view class="btn" @click="okEvent">
        <text>{{ btnData }}</text>
      </view>
    </view>

  </view>
</template>
<script>
export default {
  props: {
    title: { type: String, default: "消息" },
    show: { type: Boolean, default: false },
    btn: { type: String, default: "知道了" }
  },
  data() {
    return {
      btnData: this.ok,
      showStr: this.show ? 'show' : 'hide',
      titleData: this.title
    }
  },
  beforeMount() {
    this.titleData = this.title;
    this.btnData = this.btn;
  },
  watch: {
    btn: {
      handler(val) {
        this.btnData = val;
      },
      deep: true,
      immedaite: true
    },
    title: {
      handler(val) {
        this.titleData = val;
      },
      deep: true,
      immedaite: true
    },
    show: {
      handler(val) {
        // if (val) {
        //   uni.hideTabBar();
        // } else {
        //   uni.showTabBar()
        // }
        this.setShow(val);
      },
      deep: true,
      immedaite: true
    }
  },
  methods: {
    okEvent() {
      this.$emit("ok");
      this.setShow(false);
    },
    setShow(val) {
      this.showStr = val ? 'show' : 'hide';
    },
    cancel(){
      this.$emit("cancel");
    }
  }
}
</script>

<style scoped lang="scss">
@mixin main() {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  background: rgba(0, 0, 0, 0.4);
  z-index: 999;
}
.content {
  background-color: #fff;
  border-radius: 6px;
  width: 500rpx;
  padding: 20rpx;
  position: relative;
  .title {
    margin-top: 20rpx;
    text-align: center;
  }
  .c1 {
    margin: 40rpx 10rpx;
    min-height: 200rpx;
    font-size: 14px;
    font-family: PingFangSC, PingFangSC-Regular;
    font-weight: 400;
    text-align: justify;
    color: #2b2b2b;
    line-height: 21px;
  }
}
.hide {
  @include main();
  display: none;
}
.show {
  @include main();
  display: flex;
}
.btn {
  width: 80%;
  margin: 20rpx auto;
  height: 80rpx;
  background: linear-gradient(270deg, #4ab2a8, #49c798);
  border-radius: 4px;
  font-size: 15px;
  font-family: PingFangSC, PingFangSC-Semibold;
  font-weight: 600;
  text-align: center;
  color: #ffffff;
  line-height: 22px;
  letter-spacing: 0.8px;
  display: flex;
  justify-content: center;
  align-items: center;
  text {
    display: block;
  }
}
</style>